var Tool = require("../../../utils/ztool.js");
var util = require('../../../utils/util.js');
var tool = new Tool();
Page({
  data: {
    IDD: '',
    detail: '',
    driverlist: [],
    showModal: 0,
    showModalChange: 0,
    adddriverlist: [],
    arroriginal: [],
    drivername: '',
    driverphone: '',
    carnum: '',
    seatcount: '',
    driverid: '',
    money: '',
    searchtype: 1, //1是默认搜索司机，2是搜索车辆
    cancelornocancel: 0,//初始值是0，在有司机取消时为1，恢复时为2
    dobesure: false,//车公司确认有车
    listGuider: [],
    listChengke: [],
    //弹出框标识
    hiddenOrderPrice: true,
    OrderPrice: '',
    changepriceDriver: '',
    edittag: '',
    isregularbus: false,
    changebxname: '',
    changebcname: '',
    changebctime: '',
    apid: '',

    //车公司添加乘客参数
    newselectTagChengke: 0,
    //手输的三个参数
    newpassengername: '',
    newpassengertel: '',
    newpassengerprice: '',

    regularbuspassengerlist: [],

    isadddriver: false,
    addnewdriverkeyword: '',
    addnewdriverlist: [],
    adddriver2: false,
    deletedriverform: false,
  },


  //车公司添加乘客
  newaddchengke: function () {
    this.setData({
      newselectTagChengke: 1,
    });
  },

  //添加乘客时的三个input方法
  newinputpassengername: function (e) {
    this.setData({
      newpassengername: e.detail.value,
    });
  },

  hidenewaddchengke: function () {
    this.setData({
      newselectTagChengke: 0,
      newpassengername: '',
      newpassengertel: '',
      newpassengerprice: '',
    });
  },

  newinputpassengertel: function (e) {
    this.setData({
      newpassengertel: e.detail.value,
    });
  },

  newinputpassengerprice: function (e) {
    this.setData({
      newpassengerprice: e.detail.value,
    });
  },

  addnewchengke: function () {
    var that = this
    console.log(that.data.newpassengername)
    console.log(that.data.newpassengertel)
    console.log(that.data.newpassengerprice)

    that.setData({
      newselectTagChengke: 0,
    });

    if (that.data.newpassengername == '') {
      that.setData({
        newselectTagChengke: 1,
      });
      that.showError('请输入乘客姓名')
      return
    }

    if (that.data.newpassengertel == '') {
      that.setData({
        newselectTagChengke: 1,
      });
      that.showError('请输入乘客电话')
      return
    }

    if (that.data.newpassengertel.length != 11) {
      that.setData({
        newselectTagChengke: 1,
      });
      that.showError('请输入正确的手机号码')
      return
    }

    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (!myreg.test(that.data.newpassengertel)) {
      that.setData({
        newselectTagChengke: 1,
      });
      that.showError('请输入正确的手机号码')
      return
    }

    if (that.data.newpassengerprice == '') {
      that.data.newpassengerprice = '0'
    }

    var userInfo = wx.getStorageSync('userInfo');
    console.log(userInfo)

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/OrderAddCustHdl.ashx',
      data: {
        ID: userInfo.ZID,
        PID: 0,
        OpType: '0',
        Price: that.data.newpassengerprice,
        ctel: that.data.newpassengertel,
        cname: that.data.newpassengername,
        IDD: that.data.IDD
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //隐藏Toast
          wx.hideToast();
          //显示错误信息
          that.showError('接口请求失败，请重试')
          return
        }
        // success

        var data = tool.getRegularJson(res.data);
        var code = data.code;
        console.log(res);
        if (code == 0) {
          wx.showToast({
            title: '添加成功',
            icon: 'success',
            duration: 1000
          })
          that.setData({
            // newselectTagChengke: 0,
            newpassengername: '',
            newpassengertel: '',
            newpassengerprice: '',
          });
          setTimeout(function deletesuccess() {
            that.getDataChengke()
          }, 1000);

        } else {
          that.showError(data.msg)
        }
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  cancelpassenger: function (e) {
    var that = this
    console.log(e)

    wx.showModal({
      title: '操作确认',
      content: '是否取消 ' + e.currentTarget.dataset.ccustomername + ' 乘客',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          var userInfo = wx.getStorageSync('userInfo');
          console.log(userInfo)

          wx.request({
            url: 'https://www.lanshuicar.com/Server/CarCompany/OrderAddCustHdl.ashx',
            data: {
              ID: userInfo.ZID,
              PID: e.currentTarget.dataset.id,
              OpType: '1',
              Price: that.data.newpassengerprice,
              ctel: e.currentTarget.dataset.tel,
              IDD: that.data.IDD
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function (res) {
              if (res.statusCode == 404) {
                //接口加载失败
                console.log('加载接口错误');
                //隐藏Toast
                wx.hideToast();
                //显示错误信息
                that.showError('接口请求失败，请重试')
                return
              }
              // success

              var data = tool.getRegularJson(res.data);
              var code = data.code;
              console.log(res);
              if (code == 0) {
                wx.showToast({
                  title: '取消成功',
                  icon: 'success',
                  duration: 1000
                })
                setTimeout(function deletesuccess() {
                  that.getDataChengke()
                }, 1000);
              } else {
                that.showError(data.msg)
              }
            },
            fail: function () {
              // fail
            },
            complete: function () {
              // complete
            }
          })
        } else {
          console.log('用户点击取消')
        }
      }
    })


  },

  //修改报价
  bindchangeprice: function (e) {
    // if (this.data.detail.carBesure == 1) {
    //   this.showError('我方已确认接单，暂不能修改报价')
    //   return
    // }
    this.setData({
      hiddenOrderPrice: !this.data.hiddenOrderPrice
    })
    // this.setData({
    //   OrderPrice: ''
    // })
    // console.log(this.data.OrderPrice)
  },

  changeOrderPrice: function (e) {
    var pri = e.detail.value
    this.data.OrderPrice = pri
    console.log(this.data.OrderPrice)
  },

  cancelOrderPrice: function () {
    this.setData({
      hiddenOrderPrice: true
    });
  },

  confirmOrderPrice: function () {
    console.log(this.data.OrderPrice)
    if (this.data.OrderPrice == '') {
      this.showError('请输入我方报价')
      return
    }
    this.setData({
      hiddenOrderPrice: true
    })
    ChangePriceFun(this)
  },



  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    console.log(options)

    this.setData({
      IDD: options.IDD,
    });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    //获取订单信息
    this.getdetail();
    //获取司机和车辆信息
    this.getdriverandcar();
    this.getDataGuider();
    this.getDataChengke();
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  checkboxChange: function (e) {
    var that = this
    var useinfo = wx.getStorageSync('userInfo')
    var showuser = ''
    if (e.detail.value == true) {
      showuser = 1
    } else {
      showuser = 0
    }

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/ChangeShowUserHdl.ashx',
      data: {
        idd: that.data.IDD,
        cid: useinfo.ZID,
        showuser: showuser
      },
      method: 'GET',
      success: function (res) {
        console.log(res)

        console.log(res.data)
        if (res.data.code == 0) {
          wx.showToast({
            title: '修改成功',
          })
          if (showuser == 1) {
            that.data.checked = true
          } else {
            that.data.checked = false
          }
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          })
        }

      },
      fail: function (res) {
        console.log(res)
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })

      }
    })
  },

  //获取订单细节
  getdetail: function () {
    console.log('getdetail')
    var that = this
    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompOrders.ashx',
      data: {
        IDD: that.data.IDD,
      },
      method: 'GET',
      success: function (res) {

        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //显示错误信息
          that.showError('订单信息接口请求失败')
          that.setData({
            loadError: true
          });
          return
        }

        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.code != 0) {
          that.showError(data.msg)
        }

        if (data.data.length > 0) {
          that.setData({
            detail: data.data[0],
          });
          console.log(that.data.detail)

          if (that.data.detail.IsBanChe == 1) {
            that.setData({
              isregularbus: true
            })
            that.getregularbuspassenger()
          }

          if (that.data.detail.showUser == 0) {
            that.setData({
              checked: false
            })
          } else {
            that.setData({
              checked: true
            })
          }

          var arrdetail = that.data.detail
          var Stime = arrdetail.UseCarStartTime.substring(11, 16)
          var Etime = arrdetail.UseCarEndTime.substring(11, 16)
          console.log(Stime, Etime)
          if (Stime == '00:00' && Etime == '23:59') {
            that.setData({
              StartTime: arrdetail.UseCarStartTime.substring(0, 10),
              EndTime: arrdetail.UseCarEndTime.substring(0, 10),
            })
          } else {
            that.setData({
              StartTime: arrdetail.UseCarStartTime.substring(0, 16),
              EndTime: arrdetail.UseCarEndTime.substring(0, 16),
            })
          }
        }
      },
      fail: function () {
        console.log('加载错误');
        that.setData({
          loadError: true
        });

      }
    })
  },

  getregularbuspassenger: function () {
    var that = this
    that.data.regularbuspassengerlist = []
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Banche/GetYgListByOrder.ashx',
      data: {
        IDD: that.data.IDD,
      },
      method: 'GET',
      success: function (res) {

        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //显示错误信息
          that.showError('订单信息接口请求失败')
          that.setData({
            loadError: true
          });
          return
        }

        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          // if (that.data.detail.IsBanChe == 1 || data.data[0].bcTime != '') {
          //   for (var i = 0; i < data.data.length; i++) {
          //     data.data[i].bcTime = data.data[i].bcTime.substring(5, 16)
          //   }
          //   that.setData({
          //     isregularbus: true
          //   });
          // }

          // that.setData({
          //   driverlist: data.data
          // });

          // console.log(that.data.driverlist)
        }
      },
      fail: function () {
        console.log('加载错误');
        wx.hideToast();
        that.setData({
          loadError: true
        });

      }
    })
  },

  callpassenger: function (e) {
    console.log(e)
    var that = this
    // var phoneNumber = e.currentTarget.dataset.phone
    //测试数据
    var phoneNumber = '18550188214'
    console.log(phoneNumber)
    if (phoneNumber == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: phoneNumber,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },

  showdetail: function () {
    console.log('showdetail')
  },

  showError: function (msg) {
    var that = this;
    that.setData({
      formError: true,
      errorMessage: msg
    });

    setTimeout(function () {
      that.setData({
        formError: false,
        errorMessage: '未知错误'
      });
    }, 2000);
  },

  //获取订单有关司机和车辆安排
  getdriverandcar: function () {
    var that = this
    that.setData({
      driverlist: [],
    });
    console.log(that.data.driverlist.length)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/DriverPerson/GetDriverCarInfo.ashx',
      data: {
        IDD: that.data.IDD,
      },
      method: 'GET',
      success: function (res) {

        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //显示错误信息
          that.showError('订单信息接口请求失败')
          that.setData({
            loadError: true
          });
          return
        }

        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          if (that.data.detail.IsBanChe == 1 || data.data[0].bcTime != '') {
            for (var i = 0; i < data.data.length; i++) {
              data.data[i].bcTime = data.data[i].bcTime.substring(5, 16)
            }
            that.setData({
              isregularbus: true
            });
          }

          that.setData({
            driverlist: data.data
          });

          console.log(that.data.driverlist)
        }
      },
      fail: function () {
        console.log('加载错误');
        wx.hideToast();
        that.setData({
          loadError: true
        });

      }
    })
  },

  onShareAppMessage: function (res) {
    var useinfo = wx.getStorageSync('userInfo');
    console.log(useinfo)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      // title: '您有来自' + useinfo.CompanyName + '的新订单！',
      title: useinfo.CompanyName + '给您发送了关于' + this.data.detail.routeTitle + "的订单！",
      path: 'pages/jumppage/jumppage?jumproutetitle=' + this.data.detail.routeTitle + '&jumpCompanyName=' + useinfo.CompanyName + '&jumpshangchedidian=' + this.data.detail.GetOnPlace + '&jumpxiachedidian=' + this.data.detail.GetOffPlace + '&jumpstartime=' + this.data.detail.UseCarStartTime + '&jumpendtime=' + this.data.detail.UseCarEndTime + '&jumprouteroute=' + this.data.detail.Route,
      // imageUrl: 'http://img.yanj.cn/store/goods/3869/3869_195435ada8791c28c07df02b8b60390d.jpg_max.jpg',
      imageUrl: '../../../images/pushlogo2.png',
      success: function (res) {
        // 转发成功
        wx.showToast({
          title: '转发成功',
          icon: 'succes',
          duration: 1000,
          mask: true
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

  //输入框变化搜索
  inputchange: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    for (var i = 0; i < that.data.arroriginal.length; i++) {
      if (that.data.searchtype == 1) {
        if (that.data.arroriginal[i].sName.indexOf(keyWord) >= 0 || that.data.arroriginal[i].sTel.indexOf(keyWord) >= 0) {
          arr.push(that.data.arroriginal[i]);
        }
      } else {
        if (that.data.arroriginal[i].Cph.indexOf(keyWord) >= 0) {
          arr.push(that.data.arroriginal[i]);
        }
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      if (arr.length == 0) {
        wx.showToast({
          title: '没有对应的司机',
          icon: 'none',
          duration: 1000,
        })
      }
      that.setData({
        adddriverlist: arr
      });
    } else {
      that.setData({
        adddriverlist: that.data.arroriginal
      });
    }
  },

  inputmoney: function (e) {
    var that = this
    var money = e.detail.value

    that.setData({
      money: money
    });
  },
  inputmoneyChange: function (e) {
    var that = this
    var money = e.detail.value
    that.data.changepriceDriver = money
    // that.setData({
    //   changepriceDriver: money
    // });
    console.log(that.data.changepriceDriver)
  },


  //添加司机和车辆
  adddriver: function (e) {

    var that = this
    that.setData({
      showModal: 1
    });
  },

  //添加司机和车辆
  Changedriver: function (e) {
    var that = this
    var DriverData = e.currentTarget.dataset.driverdata
    console.log(DriverData)
    if (DriverData.IsCancel == 1) {
      that.showError('司机已取消,无法编辑')
      return
    }

    that.data.edittag = '1'
    that.setData({
      showModalChange: 1
    });
    that.setData({
      driverid: DriverData.DriverID,
      drivername: DriverData.sName,
      driverphone: DriverData.sTel,
      carnum: DriverData.CarName,
      seatcount: DriverData.Seat,
      changepriceDriver: DriverData.DriverPrice,
      changebxname: DriverData.lName,
      changebcname: DriverData.bcName,
      changebctime: DriverData.bcTime,
      apid: DriverData.ID
    })
  },


  onCancel: function () {
    this.hideModal();
  },

  hideModal: function () {
    this.setData({
      driverid: '',
      drivername: '',
      driverphone: '',
      carnum: '',
      seatcount: '',
      changepriceDriver: '',
      showModal: 0,
    });
  },
  onCancelChange: function () {
    this.hideModalChange();
  },


  hideModalChange: function () {
    this.setData({
      driverid: '',
      drivername: '',
      driverphone: '',
      carnum: '',
      seatcount: '',
      edittag: '',
      showModalChange: 0,
      apid: '',
    });
  },

  hideModal2: function () {
    this.setData({
      dobesure: false,
    });
  },

  doadddriverlist: function () {
    var that = this
    this.setData({
      showModal: 2,
      adddriverlist: [],
      arroriginal: [],
      searchtype: 1,
    });

    var useinfo = wx.getStorageSync('userInfo');
    var useid = useinfo.ZID

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
      data: {
        Id: useid,
        stype: '1',
        PageIndex: '1',
        PageSize: '100',
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          that.setData({
            adddriverlist: that.data.adddriverlist.concat(data.data),
          });

          that.setData({
            arroriginal: that.data.adddriverlist
          });

          console.log(that.data.adddriverlist)
          console.log(that.data.adddriverlist)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  clickdriver: function (e) {
    var that = this
    console.log(e)
    var driverid = e.currentTarget.dataset.idx
    console.log(driverid)

    for (var i = 0; i < that.data.adddriverlist.length; i++) {
      if (that.data.searchtype == 1) {
        if (that.data.adddriverlist[i].SijiID == driverid) {
          that.setData({
            driverid: that.data.adddriverlist[i].SijiID,
            drivername: that.data.adddriverlist[i].sName,
            driverphone: that.data.adddriverlist[i].sTel,
            carnum: that.data.adddriverlist[i].sCarNum,
            seatcount: that.data.adddriverlist[i].sCarSeatCount,
            showModal: 1
          });
        }
      } else {
        if (that.data.adddriverlist[i].Cph == driverid) {
          that.setData({
            carnum: that.data.adddriverlist[i].Cph,
            seatcount: that.data.adddriverlist[i].sCount,
          });
          if (that.data.edittag == 1) {
            that.setData({
              showModalChange: 1,
              showModal: 0,

            });
          } else {
            that.setData({
              showModal: 1
            });

          }
        }
      }
    }
  },

  confirmadd: function () {
    var that = this

    if (that.data.driverid == '') {
      that.showError('请选择司机')
      return
    }

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/OrderDriverChangeHdl.ashx',
      data: {
        operate: 'addsiji',
        IDD: that.data.IDD,
        driverid: that.data.driverid,
        money: that.data.money,
        sjcph: that.data.carnum,
        sjzws: that.data.seatcount
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)
        if (data.code == 0) {
          that.DrivergoPush()
          that.getdriverandcar()

          var pages = getCurrentPages()
          var backpage = pages[pages.length - 2]
          backpage.setData({
            backtag: 1,
          });
        }
        else {
          var msg = data.msg
          if (msg == '未获取到新的司机的ID') {
            msg = '请勿重复点击确定'
          }
          that.showError(msg)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },


  confirmaddChange: function (e) {
    var that = this

    // console.log(that.data.apid)
    // return

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/OrderDriverChangeHdl.ashx',
      data: {
        apid: that.data.apid,
        Money: that.data.changepriceDriver,
        operate: 'update',
        sjcph: that.data.carnum,
        sjzws: that.data.seatcount,
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)
        wx.showToast({
          title: '修改成功',
        })
        that.setData({
          changepriceDriver: '',
          driverid: '',
          drivername: '',
          driverphone: '',
          carnum: '',
          apid: '',
          seatcount: '',
          edittag: '',
          showModalChange: 0,
        });
        that.getdriverandcar();
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  recoverdriver: function (e) {
    var that = this
    console.log(e)
    var i = e.currentTarget.dataset.text
    var status = e.currentTarget.dataset.status
    var tel = e.currentTarget.dataset.tel
    console.log(i)

    wx.showModal({
      title: '恢复司机',
      content: '你确定恢复该司机吗？',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          that.docanceldriver(i)
          that.setData({
            cancelornocancel: 2,
          });

          //推送
          that.PushToDriverCancel(tel, status)

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  canceldriver: function (e) {
    var that = this
    console.log(e)
    var i = e.currentTarget.dataset.apid
    var status = e.currentTarget.dataset.status
    var tel = e.currentTarget.dataset.tel
    console.log(i)

    wx.showModal({
      title: '取消司机',
      content: '你确定取消该司机吗？',
      success: function (res) {
        if (res.confirm) {

          that.setData({
            cancelornocancel: 1,
          });
          that.docanceldriver3(i,tel,status)

          

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  docanceldriver: function (driverid) {
    var that = this

    var useinfo = wx.getStorageSync('userInfo')
    var tel = useinfo.Telphone
    var pwd = wx.getStorageSync('password');
    var useid = useinfo.ZID
    console.log(useinfo)

    var billidd = that.data.IDD
    var driverid = driverid
    console.log(driverid)
    var sql = 'select ID from Web_BillDriverNew where billidd=\'' + billidd + '\' and DriverID=\'' + driverid + '\''
    console.log(sql)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/InnerServer/HDC_DESEncryptHandler.ashx',
      data: {
        type: '1',
        tel: tel,
        pwd: pwd,
        sql: sql,
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          var encryptionsql = data.data[0].sql
          console.log(encryptionsql)

          that.docanceldriver2(encryptionsql)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  docanceldriver2: function (encryptionsql) {
    var that = this
    var useinfo = wx.getStorageSync('userInfo')
    var tel = useinfo.Telphone
    var pwd = wx.getStorageSync('password');
    var useid = useinfo.ZID
    var encryptionsql = encryptionsql

    wx.request({
      url: 'https://www.lanshuicar.com/Server/InnerServer/HDC_DbHelper.ashx',
      data: {
        type: '1',
        tel: tel,
        pwd: pwd,
        excute: encryptionsql,
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          var bcpid = data.data[0].ID
          console.log(bcpid)

          that.docanceldriver3(bcpid)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  docanceldriver3: function (bcpid,tel,status) {
    var that = this
    var useinfo = wx.getStorageSync('userInfo')
    var tel = useinfo.Telphone
    var pwd = wx.getStorageSync('password');
    var useid = useinfo.ZID
    var operate = ''
    if (that.data.cancelornocancel == 1) {
      operate = 'cancel'
    } else if (that.data.cancelornocancel == 2) {
      operate = 'nocancel'
    }

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/OrderDriverChangeHdl.ashx',
      data: {
        operate: operate,
        apid: bcpid,
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)
        if(data.code == '-1'){
          wx.showToast({
            title: data.msg,
            icon:'none',
          })
          return;
        }

        if (data.data.length > 0) {
          //推送
          that.PushToDriverCancel(tel, status)

          that.getdriverandcar()
          that.setData({
            cancelornocancel: 0,//操作成功后恢复cancelornocancel为0，以免影响其他司机操作
          });
          var pages = getCurrentPages()
          var backpage = pages[pages.length - 2]
          backpage.setData({
            backtag: 1,
          });

        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  doaddcarlist: function () {
    var that = this

    this.setData({
      showModal: 2,
      adddriverlist: [],
      arroriginal: [],
      searchtype: 2,
    });

    var useinfo = wx.getStorageSync('userInfo')
    var useid = useinfo.ZID
    var type = useinfo.USerType

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompOrderVehicles.ashx',
      data: {
        judge: '1',
        id: useid,
        type: type,
        PageIndex: '1',
        PageSize: '1000',
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          that.setData({
            adddriverlist: that.data.adddriverlist.concat(data.data),
          });

          that.setData({
            arroriginal: that.data.adddriverlist
          });

          console.log(that.data.adddriverlist)
          console.log(that.data.adddriverlist)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  doaddcarlist2: function () {
    var that = this

    this.setData({
      showModalChange: 0,
      showModal: 2,
      adddriverlist: [],
      arroriginal: [],
      searchtype: 2,
    });

    var useinfo = wx.getStorageSync('userInfo')
    var useid = useinfo.ZID
    var type1 = useinfo.USerType

    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompOrderVehicles.ashx',
      data: {
        judge: '1',
        id: useid,
        type: type1,
        PageIndex: '1',
        PageSize: '1000',
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          that.setData({
            adddriverlist: that.data.adddriverlist.concat(data.data),
          });

          that.setData({
            arroriginal: that.data.adddriverlist
          });

          console.log(that.data.adddriverlist)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  calldriver: function (e) {
    console.log(e)
    var phoneNumber = e.currentTarget.dataset.text
    console.log(phoneNumber)
    if (phoneNumber == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: phoneNumber,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },

  call: function (e) {
    console.log(e)
    var that = this
    var phoneNumber = e.currentTarget.dataset.phone
    console.log(phoneNumber)
    if (phoneNumber == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }

    wx.makePhoneCall({
      phoneNumber: phoneNumber,
      success: function () {
        console.log("拨打电话成功！")
      },
      fail: function () {
        console.log("拨打电话失败！")
      }
    })
  },

  inputchangecarname: function (e) {
    var that = this
    console.log(e)

    that.setData({
      carnum: e.detail.value,
    });
  },

  inputchangecarname1: function (e) {
    var that = this
    console.log(e)

    that.setData({
      seatcount: e.detail.value,
    });
  },

  inputchangedriverphone: function (e) {
    var that = this
    console.log(e)

    that.setData({
      driverphone: e.detail.value,
    });
  },

  locateDriver: function (e) {
    var that = this
    var dateEnd = e.currentTarget.dataset.idx
    var isopen = e.currentTarget.dataset.open
    console.log(dateEnd)
    var time1 = util.formatTime1(new Date())
    console.log(time1)
    if (dateEnd < time1) {
      that.showError('订单已过期')
      return
    }
    if (isopen == 0) {
      that.showError('该司机尚未开启定位功能')
      return
    }
    var driverID = e.currentTarget.id
    wx.navigateTo({
      url: '../../travelAgency/locate?IDD=' + that.data.IDD + '&DriverID=' + driverID + '&retype=3',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  reviseorder: function () {
    var that = this
    var date = new Date(that.data.detail.UseCarEndTime)
    var time1 = date.getTime()

    var nowdate = new Date();
    var time2 = nowdate.getTime()
    console.log(time2);
    if (time1 < time2){
      that.showError('已过期订单不能修改')
      // return;
    }
    // var ds = { title: that.data.detail.routeTitle }
    // JSON.stringify
    // JSON.parse

    wx.navigateTo({
      url: '../orderAdd/orderAdd?IDD=' + that.data.detail.IDD + '&pagetype=2'
      // url: '../orderAdd/orderAdd?title=' + that.data.detail.routeTitle + '&pagetype=2' + '&usecarcom=' + that.data.detail.UserCompanyName + '&usecarcomtel=' + that.data.detail.Telphone + '&usecarcomid=' + that.data.detail.WebCompanyID + '&showUser=' + that.data.detail.showUser + '&upplace=' + that.data.detail.GetOnPlace + '&downplace=' + that.data.detail.GetOffPlace + '&seatRequire=' + that.data.detail.seatRequire + '&peopleRequire=' + that.data.detail.peopleRequire + '&DayNumber=' + that.data.detail.DayNumber + '&UseCarStartTime=' + that.data.detail.UseCarStartTime + '&UseCarEndTime=' + that.data.detail.UseCarEndTime + '&QuotePrice=' + that.data.detail.QuotePrice + '&inclued=' + that.data.detail.inclued + '&Route=' + that.data.detail.Route + '&OtherRequire=' + that.data.detail.OtherRequire + '&IDD=' + that.data.IDD + '&RealName=' + that.data.detail.RealName
    })
  },

  carbesure: function () {
    var that = this
    that.setData({
      dobesure: true,
    });
  },

  onCancel2: function () {
    var that = this
    that.docarbesure('无车不接单')
  },

  confirmadd2: function () {
    var that = this
    if (this.data.detail.HopePrice == this.data.detail.QuotePrice) {
      that.docarbesure('确认有车')
    } else {
      that.showError('双方价格不平,不能确认')
    }

  },

  docarbesure: function (carbesure) {
    var that = this
    var useinfo = wx.getStorageSync('userInfo')
    var useid = useinfo.ZID
    var carbesure2 = carbesure
    console.log(useinfo, useid)
    console.log(carbesure2)
    var showusercheck = 0
    if (that.data.checked == 1) {
      var showusercheck = 1;
    }
    wx.request({
      url: 'https://www.lanshuicar.com/Server/carcompany/CarCompUpdateOrderPriceStatu.ashx',
      data: {
        idd: that.data.IDD,
        zid: useid,
        statu: carbesure2,
        stype: '2',
        showuser: showusercheck,
      },
      method: 'GET',
      success: function (res) {
        console.log(res)
        // var data = tool.getRegularJson(res.data);
        // var code = data.code
        // console.log(data)

        // if (code == 0) {
        wx.showToast({
          title: '订单状态成功',
          icon: 'success',
          duration: 2000
        })
        that.setData({
          dobesure: false,
        });
        that.getdetail();
        that.orderStatusPush(carbesure)

        var pages = getCurrentPages()
        var backpage = pages[pages.length - 2]
        backpage.setData({
          backtag: 1,
        });

        // }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },


  orderStatusPush: function (carbesure) {
    var that = this
    var content = ''
    if (carbesure == '确认有车') {
      content = '车公司接受了一个您的订单'
    } else {
      content = '车公司取消了一个您的订单'
    }

    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: that.data.detail.Telphone,
        title: '您的订单状态发生了改变',
        content: content

      },
      method: 'GET',
      success: function (res) {
        if (res.data.code == 0) {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },


  getDataGuider: function () {
    this.data.listGuider = []
    var userInfo = wx.getStorageSync('userInfo')
    var password = wx.getStorageSync('password')
    var that = this
    wx.showToast({
      title: '正在加载...',
      icon: 'loading',
      duration: 10000
    });
    wx.request({
      url: 'https://www.lanshuicar.com/Server/GetCarsGuidersCusts.ashx',
      data: {
        Tel: userInfo.Telphone,
        IDD: that.data.IDD,
        OType: 2,
        PageIndex: 1,
        PageSize: 50,
        UType: userInfo.USerType,
        UID: userInfo.pUserID
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        // success

        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //显示错误信息
          that.showError('订单信息接口请求失败')
          that.setData({
            loadError: true
          });
          return
        }

        var data = tool.getRegularJson(res.data);
        var code = data.code;
        console.log(res);
        if (code == 0) {
          that.setData({
            listGuider: that.data.listGuider.concat(data.data),
          })
          console.log('##', that.data.listGuider)
        } else {

        }
      },
      fail: function () {

      },
      complete: function () {
        wx.hideToast();
        wx.stopPullDownRefresh();
      }
    })
  },
  callPhone: function (e) {
    console.log(e)
    if (e.currentTarget.id == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id //仅为示例，并非真实的电话号码
    });
  },

  locateGuider: function (e) {
    var that = this
    var dateEnd = e.currentTarget.dataset.idx
    var isopen = e.currentTarget.dataset.open
    console.log(dateEnd)
    var time1 = util.formatTime1(new Date())
    console.log(time1)
    if (dateEnd < time1) {
      that.showError('订单已过期')
      return
    }
    if (isopen == 0) {
      that.showError('该导游尚未开启定位功能')
      return
    }
    var GuiderID = e.currentTarget.id
    wx.navigateTo({
      url: '../../travelAgency/locate?IDD=' + that.data.IDD + '&DriverID=' + GuiderID + '&retype=4',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  getDataChengke: function () {
    this.data.listChengke = []
    var userInfo = wx.getStorageSync('userInfo')
    var password = wx.getStorageSync('password')
    var that = this
    wx.showToast({
      title: '正在加载...',
      icon: 'loading',
      duration: 10000
    });
    wx.request({
      url: 'https://www.lanshuicar.com/Server/GetCarsGuidersCusts.ashx',
      data: {
        IDD: that.data.IDD,
        UType: userInfo.USerType,
        PageSize: 100,
        PageIndex: 1,
        OType: 1,
        UID: userInfo.pUserID
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        // success
        if (res.statusCode == 404) {
          //接口加载失败
          console.log('加载接口错误');
          //显示错误信息
          that.showError('订单信息接口请求失败')
          that.setData({
            loadError: true
          });
          return
        }

        var data = tool.getRegularJson(res.data);
        var code = data.code;
        console.log(res);
        if (code == 0) {
          that.setData({
            listChengke: that.data.listChengke.concat(data.data),
          })
          console.log('##11', that.data.listChengke)
        } else {

        }
      },
      fail: function () {

      },
      complete: function () {
        wx.hideToast();
        wx.stopPullDownRefresh();
      }
    })
  },

  locateChengke: function (e) {
    var that = this
    var dateEnd = e.currentTarget.dataset.idx
    var isopen = e.currentTarget.dataset.open
    console.log(dateEnd)
    var time1 = util.formatTime1(new Date())
    console.log(time1)
    if (dateEnd < time1) {
      that.showError('订单已过期')
      return
    }
    if (isopen == 0) {
      that.showError('该乘客尚未开启定位功能')
      return
    }
    var ChengkeID = e.currentTarget.id
    wx.navigateTo({
      url: '../../travelAgency/locate?IDD=' + that.data.IDD + '&DriverID=' + ChengkeID + '&retype=5',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  editdriver: function () {
    var that = this

    var useinfo = wx.getStorageSync('userInfo')
    var tel = useinfo.Telphone
    var pwd = wx.getStorageSync('password');
    var useid = useinfo.ZID
    console.log(useinfo)

    var billidd = that.data.IDD
    var driverid = that.data.driverid
    console.log(driverid)
    var sql = 'select ID from Web_BillDriverNew where billidd=\'' + billidd + '\' and DriverID=\'' + driverid + '\''
    console.log(sql)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/InnerServer/HDC_DESEncryptHandler.ashx',
      data: {
        type: '1',
        tel: tel,
        pwd: pwd,
        sql: sql,
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          var encryptionsql = data.data[0].sql
          console.log(encryptionsql)

          that.editdriver2(encryptionsql)
        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  editdriver2: function (encryptionsql) {
    var that = this
    var useinfo = wx.getStorageSync('userInfo')
    var tel = useinfo.Telphone
    var pwd = wx.getStorageSync('password');
    var useid = useinfo.ZID
    var encryptionsql = encryptionsql

    wx.request({
      url: 'https://www.lanshuicar.com/Server/InnerServer/HDC_DbHelper.ashx',
      data: {
        type: '1',
        tel: tel,
        pwd: pwd,
        excute: encryptionsql,
      },
      method: 'GET',
      success: function (res) {
        var data = tool.getRegularJson(res.data);
        console.log(data)

        if (data.data.length > 0) {
          var bcpid = data.data[0].ID
          console.log(bcpid)
          that.confirmaddChange(bcpid)
          // that.docanceldriver3(bcpid)

        }
      },
      fail: function () {
        console.log('加载错误');
      }
    })
  },

  //司机推送方法
  DrivergoPush: function () {
    var that = this
    wx.showToast({
      title: '正在加载...',
      icon: 'loading',
      duration: 10000
    });

    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: that.data.driverphone,
        title: '您有新的订单来了',
        content: '车公司给您发送了一个新的订单'
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        // success
        // var data = tool.getRegularJson(res.data);
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')
          that.setData({
            driverid: '',
            drivername: '',
            driverphone: '',
            carnum: '',
            seatcount: '',
            showModal: 0
          });

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      },
      complete: function () {
        // complete
        wx.hideToast();
        wx.stopPullDownRefresh();
      }
    })
  },

  //取消和回复司机推送方法
  PushToDriverCancel: function (tel, iscancel) {
    var that = this
    var content1 = ''
    var content2 = ''
    if (iscancel == '0') {
      content1 = '您的订单已取消'
      content2 = '车公司给您的订单发生了变更'
    } else {
      content1 = '您的订单已恢复'
      content2 = '车公司给您的订单发生了变更'
    }
    console.log(content1, content2)

    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: tel,
        title: content1,
        content: content2
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        // success
        // var data = tool.getRegularJson(res.data);
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      },
      complete: function () {
      }
    })
  },

  orderPriceChangePush: function (price) {
    var that = this
    var title = '车公司给您的订单报价已修改，请及时关注'
    var content = '报价已修改为:' + price
    wx.request({
      url: 'https://www.lanshuicar.com/Server/Weixin/WxPushHdl.ashx',
      data: {
        idd: that.data.IDD,
        tel: that.data.detail.Telphone,
        title: title,
        content: content
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        wx.hideToast();
        var code = res.data.code;
        console.log(res);
        if (code == 0) {
          console.log('post推送请求成功')

        } else {
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },

  addDriver: function () {
    var that = this
    that.setData({
      isadddriver: true,
      showModal: 0,
    });
  },

  deleteDriver: function () {
    var that = this
    that.setData({
      deletedriverform: true,
      showModal: 0,
    });
  },

  hideModal5: function () {
    var that = this
    that.setData({
      deletedriverform: false,
    });
  },

  hideModal3: function () {
    var that = this
    that.setData({
      isadddriver: false,
    });
  },

  inputchangeforadd: function (e) {
    this.setData({
      addnewdriverkeyword: e.detail.value,
    });
  },

  addfrienddriver: function () {
    var that = this
    console.log(that.data.addnewdriverkeyword)
    if (that.data.addnewdriverkeyword.length <= 0) {
      wx.showToast({
        title: '请输入搜索内容',
        icon: 'none',
        duration: 1000,
      })
      return
    }

    //搜索成功关闭原弹框
    that.setData({
      isadddriver: false,
      adddriver2: true,
    });

    that.data.arroriginal = []
    that.data.addnewdriverlist = []

    var userInfo = wx.getStorageSync('userInfo')
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
      data: {
        ID: userInfo.ZID,
        stype: 2,
        pagesize: 200,
        pageindex: 1,
        search: that.data.addnewdriverkeyword
      },
      method: 'GET',
      success: function (res) {
        // success

        var data = tool.getRegularJson(res.data);
        console.log(data)
        var code = data.code;
        if (code == 0) {
          that.setData({
            addnewdriverlist: that.data.addnewdriverlist.concat(data.data),
            addnewdriverkeyword: '',
          })
          console.log(that.data.addnewdriverlist)

          if (that.data.addnewdriverlist.length > 0) {
            that.setData({
              arroriginal: that.data.addnewdriverlist
            });
          }

          wx.hideLoading()
        } else {
          console.log('123')
          console.log(res)
        }
      },
      fail: function (res) {
        console.log(res)
        // fail
      }
    })
  },

  hideModal4: function () {
    var that = this
    that.setData({
      adddriver2: false,
    });
  },

  //输入框变化搜索
  inputchange2: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    for (var i = 0; i < that.data.arroriginal.length; i++) {
      if (that.data.searchtype == 1) {
        if (that.data.arroriginal[i].sName.indexOf(keyWord) >= 0 || that.data.arroriginal[i].sTel.indexOf(keyWord) >= 0) {
          arr.push(that.data.arroriginal[i]);
        }
      } else {
        if (that.data.arroriginal[i].Cph.indexOf(keyWord) >= 0) {
          arr.push(that.data.arroriginal[i]);
        }
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      if (arr.length == 0) {
        wx.showToast({
          title: '没有对应的司机',
          icon: 'none',
          duration: 1000,
        })
      }
      that.setData({
        addnewdriverlist: arr
      });
    } else {
      that.setData({
        addnewdriverlist: that.data.arroriginal
      });
    }
  },

  adddrivertoteam: function (e) {
    var that = this
    wx: wx.showModal({
      title: '确定添加?',
      content: '确定将这个司机加入合作团队？',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          var driverID = e.currentTarget.id
          pulltoTeam(driverID, that)
        } else {

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  deletefrienddriver: function (e) {
    var that = this
    wx: wx.showModal({
      title: '确定删除?',
      content: '确定要删除这个合作司机吗？',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          var sijiID = e.currentTarget.dataset.idx
          var PartnerID = e.currentTarget.dataset.idpartner
          deleteParnter(that, sijiID, PartnerID)
        } else {

        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  }
})


function deleteParnter(that, sijiID, PartnerID) {
  var userInfo = wx.getStorageSync('userInfo');
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
    data: {
      stype: '3',
      sijiid: sijiID,
      ID: userInfo.ID,
      partnerid: PartnerID
    },
    method: 'GET',
    success: function (res) {
      // success
      var code = res.data.code;
      if (code == 0) {
        wx.showToast({
          title: '删除成功',
        })
        // getData(that)
        that.setData({
          deletedriverform: false,
        });
      }

    },
    fail: function () {
      // fail
    }
  })

}

function pulltoTeam(sijiID, that) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
    data: {
      ID: userInfo.ZID,
      sijiid: sijiID,
      stype: 4,
      judge: 1,
    },
    method: 'GET',
    success: function (res) {
      // success
      var code = res.data.code;
      if (code == 0) {
        wx.showToast({
          title: '添加成功',
        })
        // wx.navigateBack();
        that.setData({
          adddriver2: false,
        });
      }
    },
    fail: function () {
      // fail
    }
  })
}


function ChangePriceFun(that) {
  var userInfo = wx.getStorageSync('userInfo')
  wx.showToast({
    title: '正在加载...',
    icon: 'loading',
    duration: 10000
  });
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompUpdateOrderPriceStatu.ashx',
    data: {
      idd: that.data.IDD,
      price: that.data.OrderPrice,
      stype: 1,
      zid: userInfo.ZID
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      // success
      var data = tool.getRegularJson(res.data);
      var code = data.code;
      console.log(res);
      if (code == 0) {
        wx.showToast({
          title: '修改报价成功',
        });
        that.getdetail()

        if (that.data.detail.Telphone == '') {
          console.log('return')
          return
        } else {
          //修改报价推送
          that.orderPriceChangePush(that.data.OrderPrice)
        }
      } else {
        that.showError(data.msg)

      }
    },
    fail: function () {

    },
    complete: function () {
      // complete
      wx.hideToast();
      wx.stopPullDownRefresh();
    }
  })
}